package org.minproject.my_library_back.controller;

import jakarta.annotation.Resource;
import org.minproject.my_library_back.common.CommonResponse;
import org.minproject.my_library_back.domain.Library;
import org.minproject.my_library_back.service.LibraryService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class LibraryController {
    @Resource
    private LibraryService libraryService;

    @GetMapping("/libraries/{userid}")
    public CommonResponse<List<Library>> getLibraryByUserid(@PathVariable("userid") int userid) throws Exception {
        return libraryService.getLibraryByUserid(userid);
    }

    @PostMapping("/libraries/")
    public CommonResponse<Library> addLibrary(@RequestBody Library library) throws Exception {
        return libraryService.addLibrary(library);
    }


    @PostMapping("/libraries/delete/{libraryName}")
    public CommonResponse<Library> deleteLibrary(@PathVariable("libraryName") String libraryName) throws Exception {
        return libraryService.deleteLibrary(libraryName);
    }

}
